﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Kristall.Screens;
using Microsoft.Xna.Framework.Content;
using Kristall.Managers;

namespace Kristall.Screens
{
    public class CreditsScreen : GameScreen
    {
        string _msg;

        Texture2D background;

        public CreditsScreen()
        {
            TransitionOnTime = TransitionOffTime = TimeSpan.FromSeconds(0.2f);

            StringBuilder sb = new StringBuilder();
            sb.AppendLine("Credits");
            sb.AppendLine("-------");
            sb.AppendLine("This game was made by");
            sb.AppendLine("Martin Persson and Christopher Birger");
            sb.AppendLine("for the course TDDD23");
            sb.AppendLine();
            sb.AppendLine("Press ESC or Enter");
            _msg = sb.ToString();
        }

        public override void LoadContent()
        {
            ContentManager contentManager = new ContentManager(ScreenManager.Game.Services, "Content");

            background = contentManager.Load<Texture2D>("Backgrounds/CreditScreen");
        }

        public override void HandleInput(InputState input, GameTime gameTime)
        {
            base.HandleInput(input, gameTime);

            if (!IsActive)
                return;

            if (input.IsMenuSelect || input.IsMenuCancel)
            {
                ScreenManager.AddScreen(new BackgroundScreen());
                ScreenManager.AddScreen(new MainMenuScreen());
                this.ExitScreen();
            }
        }

        public override void Draw(Microsoft.Xna.Framework.GameTime gameTime)
        {
            SpriteBatch batch = ScreenManager.SpriteBatch;
            batch.Begin();
            batch.Draw(background, ScreenManager.GraphicsDevice.Viewport.Bounds, Color.White);
            Vector2 size = ScreenManager.Font.MeasureString(_msg);
            batch.DrawString(ScreenManager.Font, _msg, (Kristall.Viewport - size) * 0.5f, Color.White);
            batch.End();

            base.Draw(gameTime);
        }
    }
}
